package com.experiment07;

import java.util.ArrayList;
import java.util.List;

public class Railway {
    public static final List<Ticket> TICKETS = create();

    public static List<Ticket> create() {
        List<Ticket> tickets = new ArrayList<>();
        for (int i = 0; i < 200; i++) {
            tickets.add(new Ticket(i, "哈尔滨", "北京"));
        }
        return tickets;
    }

    public static List<Ticket> ticketList(){
        return TICKETS;
    }
    public synchronized static Ticket provideTicket(){
        try{
            return ticketList().remove(0);
        }catch (IndexOutOfBoundsException e) {
            return null;
        }
    }
}
